package com.ndp.fb.mq.consumer.retargeting;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ndp.ec.core.CatalogService;
import com.ndp.ec.core.ProductSetService;
import com.ndp.fb.constant.ConfigConst;
import com.ndp.fb.model.fbagent.param.ApiCallBackTarget;
import com.ndp.fb.mq.consumer.AbstractPullConsumer;

/**
 * 电商的消息中转
 * Created by evan on 2016/4/15.
 */
@Component
public class RetargetingConsumerImpl extends AbstractPullConsumer {
    private static Logger logger = LoggerFactory.getLogger(RetargetingConsumerImpl.class);

    @Reference
    CatalogService catalogService;
    
    @Reference
    ProductSetService productSetService;

    @Override
    public String getTopicName() {
        return ConfigConst.MQ_SERVICES_PRODUCT_TOPIC;
    }

    @Override
    protected void consume(String tag, String keys, Object message, Map<String, String> equipment) throws Exception {
        logger.debug("AdPublishConsumerImpl tag >>>> " + tag + " keys >>>" + keys + " message >>> " + message);
        ApiCallBackTarget.Product target = (ApiCallBackTarget.Product) ApiCallBackTarget.getTargetType(tag);
        switch (target) {
            case AddCatalog:
                catalogService.createCatalogCallback(equipment, message);
                break;
            case BindCatalogPixel:
                catalogService.bindCatalogPixelCallback(equipment, message);
                break;
            case AddFeed:
                catalogService.createFeedCallback(equipment, message);
                break;
            case UpdateFeedStatus:
                catalogService.updateFeedStatusCallBack(equipment,message);
                break;
            case UpdateFeed:
                catalogService.updateFeedCallback(equipment, message);
                break;
            case CreateProductSet:
            	productSetService.createFaceBookProductSetCallBack(equipment, message);
                break;
            case UpdateProductSet:
            	productSetService.updateFaceBookProductSetCallBack(equipment, message);
                break;
            default:
                logger.warn("不识别的消息tag >>>>" + tag + " ; message >>> " + message);
        }
    }
}
